﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Helpers;
using BaseTerminalProtocol.Authorizations;

namespace BaseTerminalProtocol.TerminalActions.Agents
{
    public class GetAgentInfo
    {
        
        /// <summary>
        /// Requests the get agent info.
        /// </summary>
        /// <param name="authorization">The authorization.</param>
        /// <param name="targetAgent">The target agent.</param>
        /// <returns></returns>
        public static XmlDocument RequestGetAgentInfo(Authorizations.Authorization authorization, string targetAgent)
        {
            XmlDocument doc = XMLGate.Request_INIT(authorization);
            XmlElement xmlRoot = doc.DocumentElement;

            XmlElement xmlAgent = XMLHelper.newElement(doc, "agents");
            XmlElement xmlGetAgentInfo = XMLHelper.newElement(doc, "getAgentInfo");
            XmlElement xmlTargetAgent = XMLHelper.newElement(doc, "target-agent", targetAgent);

            xmlGetAgentInfo.AppendChild(xmlTargetAgent);
            xmlAgent.AppendChild(xmlGetAgentInfo);
            if (xmlRoot != null) xmlRoot.AppendChild(xmlAgent);

            return doc;
        }

        /// <summary>
        /// Responses the get agent info.
        /// </summary>
        /// <returns></returns>
        public static XMLGate.GateResponse ResponseGetAgentInfo(string targetAgentInfo)
        {
            try
            {
                var authorization=new Authorization();
                string request = "";
                var requestGetAgentInfo = RequestGetAgentInfo(authorization, targetAgentInfo);
                var requestSend = XMLGate.Request_SEND(requestGetAgentInfo,authorization.ServerUrl, out request);
                var response = new XMLGate.GateResponse(requestSend);
                return response;
            }
            catch (Exception ex)
            {
                Tools.Logger("GetAgentInfo : " + ex.Message, "error", "ResponseGetAgentInfo");
            }
            return null;
        }

    }
}
